package top.hserver.gateway.controller;

import top.hserver.core.ioc.annotation.Autowired;
import top.hserver.core.ioc.annotation.Controller;
import top.hserver.core.ioc.annotation.GET;
import top.hserver.core.ioc.annotation.POST;
import top.hserver.core.server.util.JsonResult;
import top.hserver.gateway.dto.GatewayRouterDTO;
import top.hserver.gateway.entity.GateWayNode;
import top.hserver.gateway.service.GatewayNodeService;
import top.hserver.gateway.service.GatewayRouterService;

/**
 * 服务节点管理
 *
 * @author hxm
 */
@Controller(value = "/v1/router/", name = "路由管理 ")
public class GateWayRouterController {

  @Autowired
  private GatewayRouterService gatewayRouterService;

  @POST("add")
  public JsonResult add(GatewayRouterDTO gatewayRouterDTO) {
    if (gatewayRouterService.add(gatewayRouterDTO)) {
      return JsonResult.ok();
    } else {
      return JsonResult.error();
    }
  }

  @POST("update")
  public JsonResult update(GatewayRouterDTO gatewayRouterDTO) {
    if (gatewayRouterService.update(gatewayRouterDTO)) {
      return JsonResult.ok();
    } else {
      return JsonResult.error();
    }
  }


  @GET("list")
  public JsonResult list(Long page, Long pageSize) {
    return JsonResult.ok().put("data", gatewayRouterService.list(page, pageSize));
  }



  @GET("remove")
  public JsonResult remove(String id) {
    if (gatewayRouterService.remove(id)) {
      return JsonResult.ok();
    } else {
      return JsonResult.error();
    }
  }
}
